# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_pyname=babel
_realname=babel
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=2.11.0
_core=41
pkgrel=1
pkgdesc="A collection of tools for internationalizing Python applications (mingw-w64)"
url="https://babel.pocoo.org/"
license=('spdx:BSD-3-Clause')
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
depends=("${MINGW_PACKAGE_PREFIX}-python-pytz")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-pytest"
              "${MINGW_PACKAGE_PREFIX}-python-pytest-runner"
              "${MINGW_PACKAGE_PREFIX}-python-freezegun")
source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/python-babel/babel/archive/v${pkgver}.tar.gz"
        "cldr-core-${_core}.zip::http://unicode.org/Public/cldr/${_core}/core.zip"
        "cldr-common-${_core}.0.zip::http://unicode.org/Public/cldr/${_core}/cldr-common-${_core}.0.zip")
noextract=("cldr-core-${_core}.zip" "cldr-common-${_core}.0.zip")
sha256sums=('ae1eef5784c3399df3df9ceb62f1236d0347b0d1f6ac15d22234ff75eccbe470'
            '823c6170c41e2de2c229574e8a436332d25f1c9723409867fe721e00bc92d853'
            '823c6170c41e2de2c229574e8a436332d25f1c9723409867fe721e00bc92d853')

prepare() {
  rm -rf "python-build-${MSYSTEM}" | true
  cp -r "${_pyname}-${pkgver}" "python-build-${MSYSTEM}"
  cp "${srcdir}"/cldr-core-${_core}.zip "python-build-${MSYSTEM}"/cldr/cldr-core-${_core}.zip
  cp "${srcdir}"/cldr-common-${_core}.0.zip "python-build-${MSYSTEM}"/cldr/cldr-common-${_core}.0.zip
}

build() {
  msg "Python build for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
      ${MINGW_PREFIX}/bin/python setup.py import_cldr
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
      ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  msg "Python test for ${MSYSTEM}"
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
      TZ=UTC ${MINGW_PREFIX}/bin/python setup.py pytest || true
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/LICENSE" "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"

  for _f in "${pkgdir}${MINGW_PREFIX}"/bin/*-script.py; do
    sed -e '1 { s/^#!.*$// }' -i ${_f}
  done
}
